package com.socialuni.center.web.serive.talk;

import com.socialuni.sdk.api.model.QO.talk.SocialUserTalkQueryQO;
import com.socialuni.sdk.api.model.RO.talk.SocialTalkRO;
import com.socialuni.center.web.utils.CenterUserUtil;
import com.socialuni.center.web.utils.UnionIdDbUtil;
import com.socialuni.sdk.factory.TalkROFactory;
import com.socialuni.sdk.model.DO.talk.TalkDO;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.store.TalkQueryStore;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qinkaiyuan
 * @date 2020-05-16 20:11
 */
@Service
public class CenterQueryUserTalksService {
    @Resource
    TalkQueryStore talkQueryStore;

    public List<SocialTalkRO> queryUserTalks(SocialUserTalkQueryQO queryVO) {

        Integer userId = UnionIdDbUtil.getUserIdByUid(queryVO.getUserId());

        //获取自己的user
        UserDO mineUser = CenterUserUtil.getMineUser();

        List<Integer> talkIds = UnionIdDbUtil.getContentIdsByTalkUnionIds(queryVO.getTalkIds());

        List<TalkDO> talks = talkQueryStore.queryUserTalks(talkIds, userId, mineUser);

        return talks.stream().map(talkDO -> TalkROFactory.newFollowUserTalkRO(mineUser, talkDO)).collect(Collectors.toList());
    }
}
